const base_url = "http://172.16.8.167:3000";
const xxm_url = "https://tea.qingnian8.com/api/bizhi/"; //壁纸源来自咸虾米壁纸
const noticeRequest = (params) =>{
	let url = params.url;
	let method = params.method || "POST";//如果未传值，默认为post方法
	let data = params.data || {} ; //默认为空
	let header = { 'Content-Type': 'application/json' } ;// token得动态拿
	//获取token
	if(uni.getStorageSync("token")) header['Authorization'] = 'Bearer ' + uni.getStorageSync("token");
	return new Promise((resolve,reject)=>{
		uni.request({
			url:base_url + url,
			method:method,
			header:header,
			data:data,
			success:resolve,
			fail:reject

		})
	});
}
const request = (params) => {
	let url = params.url;
	let method = params.method || "GET";//如果未传值，默认为GET方法
	let data = params.data || {} ; //默认为空
	let header = { 'access-key': 'haomingze' } ;// 令牌
	return new Promise((resolve,reject)=>{
		uni.request({
			url:xxm_url+url,
			method:method,
			header:header,
			data:data,
			timeout:5000,
			success:res=>{
				if(res.data.errCode===0){
					resolve(res)
				}else if(res.data.errCode === 400){
					uni.showModal({
						title:"错误提示",
						content:res.data.errMsg,
						showCancel:false
					})
					reject(res)
				}else{
					uni.showToast({
						title:res.data.errMsg,
						icon:"none"
					})
					reject(res)
				}				
			},
			fail:err=>{
				reject(err)
			}
		});
	});
}
export default {
	//用户个人信息
	userInfo(){
		return request({
			url:'userInfo'
		});
	},
	//获取Banner接口
	getBanner(){
		return request({
			url:"homeBanner",
			method:"GET"
		});
	},
	//每日推荐（随机9张壁纸）
	getRandomWall(){
		return request({
			url:'randomWall',
			method:'GET'
		});
	},
	//单张壁纸
	detailWall(params={}){
		return request({
			url:'detailWall',
			data:params
		})
	},
	//获取公告接口
	getNotice(params={}){
		return noticeRequest({
			url:'/getnotice',
			method:'get',
			data:params
		}).then(resp=>{
			return resp.data.list;
		});
	},
	//获取分类列表
	getClassify(params={}){
		return request({
			url:'classify',
			method:"GET",
			data:params
		});
	},
	//获取分类详情
	getWalllist(params){
		return request({
			url:'wallList',
			method:'GET',
			data:params
		});
	},
	//为壁纸评分
	setupScore(params={}){
		return request({
			url:'setupScore',
			method:'GET',
			data:params
		});
	},
	//壁纸下载
	downloadWall(params={}){
		return request({
			url:'downloadWall',
			method:'GET',
			data:params
		});
	},
	//我的评分/下载列表
	userWallList(params={}){
		return request({
			url:'userWallList',
			data:params
		});
	},
	//壁纸公告列表
	wallNewsList(params={}){
		return request({
			url:'wallNewsList',
			data:params
		});
	},
	//公告详情
	wallNewsDetail(params={}){
		return request({
			url:'wallNewsDetail',
			data:params
		})
	},
	//搜索详情
	searchWall(params={}){
		return request({
			url:'searchWall',
			data:params
		});
	}
}